﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 碧蓝肝帝
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();           
        }
      
        /// <summary>
        /// 加载界面时发生
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form3_Load(object sender, EventArgs e)
        {
            numericUpDown1.Value = Settings1.Default.threshold;
            numericUpDown5.Value = Settings1.Default.map_threshold;
            textBox2.Text = Recognition.url_api;
            numericUpDown2.Value = Settings1.Default.Moving_number;
            textBox1.Text = Settings1.Default.Width_X.ToString();
            textBox3.Text = Settings1.Default.Height_Y.ToString();
            comboBox1.Text = (string)comboBox1.Items[0];
            numericUpDown3.Value = Settings1.Default.Sign_X;
            numericUpDown4.Value = Settings1.Default.Sign_Y;
            numericUpDown3.Maximum = Work.rect.Width + Work.rect.X;
            numericUpDown4.Maximum = Work.rect.Height + Work.rect.Y;
            textBox4.Text = "R:" + Settings1.Default.Sign_R.ToString() + " G:" + Settings1.Default.Sign_G.ToString() + " B:" + Settings1.Default.Sign_B.ToString();
        }

        /// <summary>
        /// 关闭界面是发生
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form3_FormClosed(object sender, FormClosedEventArgs e)
        {
                       
        }

        /// <summary>
        /// 程序地址
        /// </summary>
        public string dir = AppDomain.CurrentDomain.BaseDirectory;

        /// <summary>
        /// 显示坐标设置文件内容
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string dir_1 = dir + @"\Data\";
            if (comboBox1.Text == "Activity")
            {
                dir_1 += "special_files.txt";
            }
            else
            {
                dir_1 += comboBox1.Text + ".txt";
            }
            Form2 form2 = new Form2
            {
                save_class = 1
            };
            form2.Append_setting(dir_1);
            form2.StartPosition = FormStartPosition.CenterParent;
            form2.ShowDialog();
        }

        /// <summary>
        /// 显示满员时强化设置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("步骤前方建议添加不同数字，防止重复，步骤格式如:  56确定:568,699");
            Form2 form2 = new Form2()
            {
                save_class = 2
            };
            form2.Append_intensify();
            form2.StartPosition = FormStartPosition.CenterParent;
            form2.ShowDialog();
        }

        /// <summary>
        /// 取消按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {
            Close();
        }

        /// <summary>
        /// 确定保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {              
                Settings1.Default.threshold = numericUpDown1.Value;
                Settings1.Default.map_threshold = numericUpDown5.Value;
                Recognition.url_api = textBox2.Text;
                Settings1.Default.Moving_number = (int)numericUpDown2.Value;
                Settings1.Default.Width_X = Convert.ToInt32(textBox1.Text);
                Settings1.Default.Height_Y = Convert.ToInt32(textBox3.Text);
                Settings1.Default.Sign_X = (int)numericUpDown3.Value;
                Settings1.Default.Sign_Y = (int)numericUpDown4.Value;
                Settings1.Default.Save();
                Close();
            }
            catch
            {
                MessageBox.Show("输入格式错误");
            }
            
        }

        private void button5_Click(object sender, EventArgs e)
        {
            int x = (int)(numericUpDown3.Value - Work.rect.X);
            int y = (int)(numericUpDown4.Value - Work.rect.Y);
            Bitmap bitmap = Work.GetScreen();               
            Color color = bitmap.GetPixel(x,y);          
            byte r = color.R;
            byte g = color.G;
            byte b = color.B;
            textBox4.Text = "R:" + r.ToString() + "G:" + g.ToString() + "B:" + b.ToString();
            
        }
        
        
    }
}
